#include "Test.Application.h"

#undef  APP_NAME
#define APP_NAME	TestGLExt
#undef  APP_BASE
#define APP_BASE	TestApp


class APP_NAME : public APP_BASE
{
public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}

	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->Clear( true, true, false );
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		using namespace gles;

		string	s;

		s	<< "max cube map size: " << gles::C_GL_MAX_CUBE_MAP_TEXTURE_SIZE << '\n'
			<< "max frag uniform vec: " << gles::C_GL_MAX_FRAGMENT_UNIFORM_VECTORS << '\n'
			<< "max renderbuffer size: " << gles::C_GL_MAX_RENDERBUFFER_SIZE << '\n'
			<< "max texture image units: " << gles::C_GL_MAX_TEXTURE_IMAGE_UNITS << '\n'
			<< "max texture size: " << gles::C_GL_MAX_TEXTURE_SIZE << '\n'
			<< "max vertex attribs: " << gles::C_GL_MAX_VERTEX_ATTRIBS << '\n'
			<< "max vertex uniform vec: " << gles::C_GL_MAX_VERTEX_UNIFORM_VECTORS << '\n'
			<< "max viewport dims: " << gles::C_GL_MAX_VIEWPORT_DIMS[0] << ", " << gles::C_GL_MAX_VIEWPORT_DIMS[1] << '\n'
			<< "max 3d tex size: " << gles::OES_texture_3D::C_GL_MAX_3D_TEXTURE_SIZE << ", sup: " << gles::OES_texture_3D::IsSupported() << '\n'
			<< "miltisampled fbo: " << gles::EXT_multisampled_render_to_texture::C_GL_MAX_SAMPLES << ", sup: " << gles::EXT_multisampled_render_to_texture::IsSupported() << '\n'
			<< "max anisotropy: " << gles::EXT_texture_filter_anisotropic::C_GL_MAX_TEXTURE_MAX_ANISOTROPY << ", sup: " << gles::EXT_texture_filter_anisotropic::IsSupported() << '\n'
			<< "extensions:\n"
			<< "texture rg: " << gles::EXT_texture_rg::IsSupported() << '\n';

		WARNING( s.cstr() );

		TestTexFormat();

		APP_BASE::OnEnter();
	}

	void TestTexFormat ()
	{
		using namespace gles;

		GLuint id = 0;
		GL_CALL( glGenTextures( 1, &id ) );

		GL_CALL( glBindTexture( GL_TEXTURE_2D, id ) );
		GL_CALL( glTexImage2D( GL_TEXTURE_2D, 0, gles::EXT_texture_rg::GL_RG, 128, 128, 0,
								gles::EXT_texture_rg::GL_RG, GL_UNSIGNED_BYTE, null ) );

		GL_CALL( glDeleteTextures( 1, &id ) );
	}

	void OnExit () override
	{
		APP_BASE::OnExit();
	}
};